package com.cdtye.itps.cms.service.datasysn;

import com.cdtye.itps.cms.dao.defect.entity.JcwDefectInfoPhoto;
import com.cdtye.itps.cms.dao.detect.JcjcDefectGradeSection;
import com.cdtye.itps.cms.dao.detect.JcjcDefectInfoSection;
import com.cdtye.itps.cms.dao.detect.JcjcDefectSourceTypeSection;
import com.cdtye.itps.cms.dao.detect.JcjcDefectTypeSection;
import com.cdtye.itps.cms.service.defect.JcjcDefectSourceTypeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * modify by 20220530
 */
@Service
@Slf4j
public class JcjcHandleTmisService {

    @Autowired
    private JcwDefectTypeService jcwDefectTypeService;

    @Autowired
    private JcjcDefectGradeService jcjcDefectGradeService;

    @Autowired
    private JcjcDefectSourceTypeService jcjcDefectSourceTypeService;

    @Autowired
    private JcjcDefectInfoService jcjcDefectInfoService;

    @Autowired
    private JcjcDefectInfoPhotoService jcjcDefectInfoPhotoService;

    /**
         * 查询所有缺陷分类，用于验证  --段级库
     *
     * @return key:缺陷分类名称，value:缺陷分类数据
     */
    public Map<String, JcjcDefectTypeSection> findDefectTypesMapSection(String defectTypeName, String parentId) {
        List<JcjcDefectTypeSection> datas = this.findDefectTypeListByParams(defectTypeName, parentId);

        Map<String, JcjcDefectTypeSection> map = datas.stream().filter(o -> StringUtils.isNotBlank(o.getDefectTypeName()))
                .collect(Collectors.toMap(JcjcDefectTypeSection::getDefectTypeName, o -> o, (k1, k2) -> k1));

        return map;
    }

    /**
     * 多数据源缺陷分类
     *
     */
    public List<JcjcDefectTypeSection> findDefectTypeListByParams(String defectTypeName, String parentId) {
        return jcwDefectTypeService.findDefectTypeListByParamsTmis(defectTypeName, parentId);
    }

    /**
     * 查询所有缺陷等级，用于验证  --段级库
     *
     * @return key:缺陷等级名称，value:缺陷等级数据
     */
    public Map<String, JcjcDefectGradeSection> findDefectGradesMapSection(String defectGradeName) {
        List<JcjcDefectGradeSection> datas = this.findDefectGradeListByParams(defectGradeName);

        Map<String, JcjcDefectGradeSection> map = datas.stream().filter(o -> StringUtils.isNotBlank(o.getDefectGradeName()))
                .collect(Collectors.toMap(JcjcDefectGradeSection::getDefectGradeName, o -> o, (k1, k2) -> k1));

        return map;
    }

    /**
     * 多数据源缺陷分类
     *
     */
    public List<JcjcDefectGradeSection> findDefectGradeListByParams(String defectGradeName) {
        return jcjcDefectGradeService.findDefectGradeListByParamsTmis(defectGradeName);
    }

    /**
     * 查询接触网缺陷来源
     *
     */
    public JcjcDefectSourceTypeSection findDefectSourceTypeId() {
        return jcjcDefectSourceTypeService.findDefectSourceTypeByIdTmis("6C");

    }

    public List<JcjcDefectInfoSection> selectIdTmisDefectInfo(JcjcDefectInfoSection jdis){
        return jcjcDefectInfoService.selectIdDefectInfoTmis(jdis);
    }

    public boolean insertTimsDefectInfo(JcjcDefectInfoSection jcjcDefectInfoSection){
        return jcjcDefectInfoService.insertDefectInfoTmis(jcjcDefectInfoSection);
    }

    public int updateTmisDefectInfo(JcjcDefectInfoSection jdis){
        return jcjcDefectInfoService.updateDefectInfoTmis(jdis);
    }

    public boolean insertDefectInfoPhoto(List<JcwDefectInfoPhoto> jdiList){
        return jcjcDefectInfoPhotoService.insertDefectInfoPhotoTmis(jdiList);
    }

}
